package com.stevenmoon.csdnplus.util;

import com.google.gson.reflect.TypeToken;
import com.stevenmoon.csdnplus.app.AppService;

import java.util.Map;

/**
 * Created by WangJun on 2016/4/8.
 */
public class GsonUtil {

    private GsonUtil(){}

    public static Map<String,String> convertBean2Map(Object reqBean){
        String json = AppService.getInstance().getGson().toJson(reqBean);
        return  AppService.getInstance().getGson().fromJson(
                json,new TypeToken<Map<String,String>>(){}.getType());
    }

    public static String toJsonString(Object object){
        return AppService.getInstance().getGson().toJson(object);
    }

    public static <T> T toObject(String jsonString, Class<T> c){
        return AppService.getInstance().getGson().fromJson(jsonString, c);
    }
}
